package com.zcy.datasource;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by join on 2017/7/3.
 */
public class DynamicDataSourceContextHolder {

    protected static final String WRITE_TYPE = "write";
    protected static final String READ_TYPE = "read";

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
    public static List<String> readSourceIds = new ArrayList<>();

    public static void write(){
        setDataSourceType(WRITE_TYPE);
    }

    public static void read(){
        setDataSourceType(READ_TYPE);
    }

    public static void setDataSourceType(String dataSourceType) {
        contextHolder.set(dataSourceType);
    }

    public static String getDataSourceType() {
        return contextHolder.get();
    }

    public static void clearDataSourceType() {
        contextHolder.remove();
    }

}
